Repository navigation
fix(middleware): let a route fix the node type to an application - #3415
Draft
rubenvdlinde wants to merge 1 commit into
Draft
rubenvdlinde wants to merge 1 commit into
rubenvdlinde wants to merge 1 commit into
Conversation
RequirePermission takes 'context' as a fixed type, so the request cannot name another node type and get the permission checked on a table or view with the same id. The application routes use it. Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
3 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The routes of an application check permissions with
#[RequirePermission(..., typeParam: 'context')]. The middleware reads the node type from a request parameter namedcontext. None of these routes has that parameter in its URL, so a client can send?context=table(or0) and have the permission checked on the table with the same id instead of on the application.The same flaw lets someone outside an application read its pages: whoever owns a table with the same id as the application gets 200 on
GET /api/2/contexts/{contextId}/pages/{pageId}?context=table. With the fixed type that answers 404.RequirePermissionnow acceptstype: 'context', a fixed node type the request cannot change. The nine application routes inContextControllerandContextPageControlleruse it, and notypeParam: 'context'is left on main.Found by @blizzz in the review of #3135. The menu routes there move to the fixed type once both have landed.
How it was tested
New
tests/unit/Middleware/PermissionMiddlewareTest.php: with the type fixed, the application is checked whatevercontextthe request sends (none,table,0or1), and a manager passes. Full unit suite (788 tests) and psalm green.How it was tested on a live instance
On Nextcloud 34 with PostgreSQL, with an owner, a reader and an outside user, where the reader owns a table with the same id as the application and the outside user owns a table with the id of an application they are not in. On main the reader created a page with
?context=tableand with?context=0and renamed the owner's page (200 each), and the outside user read a page of the application with?context=table(200). With this change the same requests answer 403 for the reader and 404 for the outside user, also against the application created on main; the owner still creates and renames pages and exports the scheme (200), and the reader still reads the application (200).🖼️ Screenshots
None, no visible change.
🏁 Checklist
/backport to stable2🤖 AI (if applicable)